<?php
class contFilediff extends coreController
{
    private $aDirInfo = array();
    
    public function index()
    {
        $sDir = '/lib';
        
        $sServerDefault = 'D:/CAFE24/CAFE24_TMEP';
        $this->getDirSearch($sServerDefault, $sDir);
        $aServerFile = $this->aDirInfo;
        
        //echo '<pre>';
        //print_r($aServerFile);
        
        unset($this->aDirInfo);
        
        $sLocalDefault = 'D:/CAFE24/CAFE24_PROJECT/datahub';
        $this->getDirSearch($sLocalDefault, $sDir);
        $aLocalFile = $this->aDirInfo;
        
        //echo '<pre>';
        //print_r($aLocalFile);
        
        $aCheckInfo = array();
        foreach ($aServerFile as $_path => $aVal) {
            // 파일이 없는 경우
            if (empty($aLocalFile[$_path])) {
                $aCheckInfo['nofile'][] = $_path;
                continue;
            }
            
            if ($aVal['size'] != $aLocalFile[$_path]['size']) {
                $aCheckInfo['diff'][] = $_path;
            }
        }
        
        echo '<pre>';
        print_r($aCheckInfo);
    }
    
    private function getDirSearch($sPathDefault, $sDir)
    {
        $sPath = $sPathDefault.$sDir;
        //$sPath = 'D:/CAFE24/CAFE24_TMEP/lib';
        
        $aDirs = libFileSearch::getDirList($sPath);
    
        $iCount = count($aDirs);
        for ($i = 0; $i < $iCount; $i++) {
            $_aTmp = $aDirs[$i];
    
            if ($_aTmp['type'] == 'dir') {
                $_sPath = $sDir.'/'.$_aTmp['name'];
                
                //$aDirInfo['dir'][] = $_sPath;
                
                $this->getDirSearch($sPathDefault, $_sPath);
                
            } else if ($_aTmp['type'] == 'file') {
                //$this->aDirInfo['file'][] = $sPath.'/'.$_aTmp['name'];
                
                $_path = $sDir.'/'.$_aTmp['name'];
                
                //$_aTmp['path'] = $_path;
                
                $this->aDirInfo[$_path] = $_aTmp;
            }
        }
    }
}